<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="账单日期">
              <j-date class="query-group-cust" v-model="queryParam.date_begin" placeholder="请选择开始日期" />
              <span class="query-group-split-cust"></span>
              <j-date class="query-group-cust" v-model="queryParam.date_end" placeholder="请选择结束日期" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="收款方账户名称">
              <a-input v-model="queryParam.payeeName" placeholder="请输入收款方账户名称" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
            <!--              <a-form-item label="本次查询的汇总金额(单位元)">-->
            <!--            <a-input class="query-group-cust" v-model="queryParam.money_begin" placeholder="请输入最开始值"/>-->
            <!--            <span class="query-group-split-cust"></span>-->
            <!--            <a-input class="query-group-cust" v-model="queryParam.money_end" placeholder="请输入最结束值"/>-->
            <!--          </a-form-item>-->
            <!--        </a-col>-->
            <!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
            <!--            <a-form-item label="返回查询的结果条数">-->
            <!--          <a-input v-model="queryParam.count" placeholder="请输入返回查询的结果条数"/>-->
            <!--        </a-form-item>-->
            <!--      </a-col>-->

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="收款方开户行号">
                <a-input v-model="queryParam.payeeBankDeposit" placeholder="请输入收款方开户行号" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24" v-is-group>
              <a-form-item label="所属公司">
                <j-company-select-tag placeholder="请选择所属公司" v-model="queryParam.companyId" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
      <!--      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>-->
      <a-button type="primary" v-has="'statementAccount:export'" icon="download" @click="handleExportXls('对账单信息')">导出
      </a-button>
      <a-button type="primary" v-is-group v-has="'statementAccount:download'" icon="download" @click="statementAccountOperation()">下载对账单
      </a-button>
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item v-has="'statementAccount:delete'" key="1" @click="batchDel">
            <a-icon type="delete" />
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <!--      <a-alert type="info" showIcon style="margin-bottom: 16px;">-->
      <!--        <template slot="message">-->
      <!--          <span>已选择</span>-->
      <!--          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>-->
      <!--          <span>项</span>-->
      <!--          <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--        </template>-->
      <!--      </a-alert>-->


      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-wrap"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :scroll="{  y: screenHeight }"
        :expandedRowKeys="expandedRowKeys"
        @expand="handleExpand"
        @change="handleTableChange"
      >
        <!--        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->
        <!--        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"-->
        <!--        @change="handleTableChange"-->

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
          <statement-account-details-sub-table :record="record" />
          <!--          <a-tabs tabPosition="top">-->
          <!--            <a-tab-pane tab="对账单详情" key="statementAccountDetails" forceRender>-->
          <!--              <statement-account-details-sub-table :record="record"/>-->
          <!--            </a-tab-pane>-->
          <!--          </a-tabs>-->
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;" />
          </div>
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              <span>更多 <a-icon type="down" /></span>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <statement-account-modal ref="modalForm" @ok="modalFormOk" />
    <StatementAccountOperation-modal ref="statementAccountOperationForm" @ok="modalFormOk" />

  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import StatementAccountModal from './modules/StatementAccountModal'
import StatementAccountOperationModal from './modules/StatementAccountOperationModal'
import StatementAccountDetailsSubTable from './subTables/StatementAccountDetailsSubTable'
import JDate from '@/components/jeecg/JDate.vue'
import '@/assets/less/TableExpand.less'
import JCompanySelectTag from '@comp/jeecg/JCompanySelectTag'

export default {
  name: 'StatementAccountList',
  mixins: [JeecgListMixin],
  components: {
    StatementAccountModal,
    JCompanySelectTag,
    StatementAccountDetailsSubTable,
    StatementAccountOperationModal,
    JDate
  },
  data () {
    return {
      description: '对账单信息列表管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
        },
        {
          title: '账单日期',
          align: 'center',
          dataIndex: 'date'
        },
        {
          title: '收款方账户名称',
          align: 'center',
          dataIndex: 'payeeName'
        },
        {
          title: '汇总金额(单位元)',
          align: 'center',
          dataIndex: 'money',
          customRender: function (text) {
            if (!text) {
              text = 0
            }
            return text.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' })
          }
        },
        {
          title: '收款方开户行号',
          align: 'center',
          dataIndex: 'payeeBankDeposit'
        },
        {
          title: '条数',
          align: 'center',
          dataIndex: 'count'
        },
        {
          title: '收款方账号',
          align: 'center',
          dataIndex: 'payeeAccount'
        },
        {
          title: '下载时间',
          align: 'center',
          dataIndex: 'updateTime'
        }
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
      // 字典选项
      dictOptions: {},
      // 展开的行
      expandedRowKeys: [],
      url: {
        list: '/zcgl/statementAccount/list',
        delete: '/zcgl/statementAccount/delete',
        deleteBatch: '/zcgl/statementAccount/deleteBatch',
        exportXlsUrl: '/zcgl/statementAccount/exportXls',
        importExcelUrl: '/zcgl/statementAccount/importExcel'
      }
    }
  },
  computed: {
    importExcelUrl () {
      return window._CONFIG['domianURL'] + this.url.importExcelUrl
    }
  },
  methods: {

    initDictConfig () {
      this.addColumns()
    },
    statementAccountOperation () {
      this.$refs.statementAccountOperationForm.show()
    },

    handleExpand (expanded, record) {
      this.expandedRowKeys = []
      if (expanded === true) {
        this.expandedRowKeys.push(record.id)
      }
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
</style>